package s.k.gui.webtest.element.tools;

import s.k.gui.webtest.element.locator.Locator;
import s.k.gui.webtest.element.locator.LocatorChain;
import s.k.gui.webtest.element.locator.LocatorValue;
import s.k.gui.webtest.page.Part;

public class WebElementExist {

	protected LocatorValue webElement;

	protected LocatorChain infoChain;

	protected Locator locator;

	public WebElementExist(LocatorValue webElement) {

		this.webElement = webElement;

		this.infoChain = webElement.getInfoChain();

		this.locator = webElement.getLocator();

	}

	protected void initComment() {

		if (webElement instanceof Part || hasPart()) {

			webElement.setComment("");

			comComment();

		} else {

			if (webElement.getComment().contains("-->"))

				return;

			comComment();

		}
	}

	private boolean hasPart() {

		for (LocatorValue element : infoChain.getInfoNodes()) {

			if (element instanceof Part)

				return true;

		}

		return false;

	}

	private void comComment() {

		StringBuilder commentTemp = new StringBuilder();

		for (int i = 0; i < infoChain.getInfoNodes().size(); i++) {

			commentTemp.append(infoChain.getInfoNodes().get(i).getComment()
					+ "-->");

		}
		commentTemp.append(webElement.getComment());

		webElement.setComment(commentTemp.toString());

	}

	/**
	 *
	 * */
	public boolean isElementExist(int WaitCount) {

		return false;
	}

	/** ֻ�ȴ�һ�� */
	public boolean isElementExistForCheckOnce() {

		return false;
	}

}
